package com.nbjtjc.safe.api.edu;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.nbjtjc.safe.annotation.SysLog;
import com.nbjtjc.safe.bean.Result;
import com.nbjtjc.safe.mapper.edu.EduEntryTrainingMapper;
import com.nbjtjc.safe.model.edu.EduEntryTraining;
import com.nbjtjc.safe.model.sys.SysDept;
import com.nbjtjc.safe.service.edu.EduEntryTrainingService;
import com.nbjtjc.safe.service.sys.SysDeptService;
import com.nbjtjc.safe.util.MyShiroUtils;
@RestController
@CrossOrigin("*")
@RequestMapping("/eduEntryTraining")
public class EduEntryTrainingController {
	@Autowired
	private EduEntryTrainingService eduEntryTrainingService;
	@Autowired
	private SysDeptService sysDeptService;
	@Autowired
	private EduEntryTrainingMapper eduEntryTrainingMapper;
	

	  @RequestMapping(value = "/add",method = {RequestMethod.POST})
	  @SysLog("批量添加三级培训")
	    public Result add(@RequestBody EduEntryTraining eduEntryTraining){
	        Result result=new Result();
	        try {
	            result=eduEntryTrainingService.add(eduEntryTraining);
	        } catch (Exception e) {
	            e.printStackTrace();
	            result.setFalse(e.getMessage());
	        }
	        return result;
	    }
	  
	  @RequestMapping(value = "/addAndUpdateOne",method = {RequestMethod.POST})
	  @SysLog("添加或更新单个三级培训")
	    public Result addAndUpdateOne(@RequestBody EduEntryTraining eduEntryTraining){
	        Result result=new Result();
	        try {
	            result=eduEntryTrainingService.addAndUpdateOne(eduEntryTraining);
	        } catch (Exception e) {
	            e.printStackTrace();
	            result.setFalse(e.getMessage());
	        }
	        return result;
	    }
	  
	  @RequestMapping(value = "/batchInputScores",method = {RequestMethod.POST})
	  @SysLog("批量录入三级培训成绩")
	    public Result batchInputScores(@RequestBody EduEntryTraining eduEntryTraining){
	        Result result=new Result();
	        try {
	            result=eduEntryTrainingService.batchInputScores(eduEntryTraining);
	        } catch (Exception e) {
	            e.printStackTrace();
	            result.setFalse(e.getMessage());
	        }
	        return result;
	    }
	 
	  @RequestMapping(value = "/delete",method = {RequestMethod.POST})
	  @SysLog("删除三级培训")
	    public Result delete(@RequestBody EduEntryTraining eduEntryTraining) {
	        Result result=new Result();
	        try {
	            result=eduEntryTrainingService.delete(eduEntryTraining);
	        } catch (Exception e) {
	            e.printStackTrace();
	            result.setFalse(e.getMessage());
	        }
	        return result;
	    }
	  
	 
	  @RequestMapping(value = "/find", method = {RequestMethod.POST})
	  public Result find(@RequestBody EduEntryTraining eduEntryTraining) {
	        Result result = new Result();
	        try {
	            result = eduEntryTrainingService.findDetail(eduEntryTraining);
	        } catch (Exception e) {
	            e.printStackTrace();
	            result.setFalse(e.getMessage());
	        }
	        return result;
	    }
	  
	  @RequestMapping(value = "/compFindDetail", method = {RequestMethod.POST})
	  public Result compFindDetail(@RequestBody EduEntryTraining eduEntryTraining) {
	        Result result = new Result();
	        try {

	        	List<Integer> deptIds= new ArrayList();
	        	deptIds.add(MyShiroUtils.getCompanyId());
	        	deptIds=sysDeptService.getAllSubCompanyId(MyShiroUtils.getCompanyId(), deptIds);
        		PageHelper.startPage(eduEntryTraining.getPageCurrent(), eduEntryTraining.getPageSize());

	        	List<EduEntryTraining> eduEntryTrainings  = eduEntryTrainingMapper.compFindDetail(eduEntryTraining,deptIds);
	        	
	        	result.setData(new PageInfo<>(eduEntryTrainings));
	        } catch (Exception e) {
	            e.printStackTrace();
	            result.setFalse(e.getMessage());
	        }
	        return result;
	    }
	  
	  @RequestMapping(value = "/findSimple", method = {RequestMethod.POST})
	  public Result findSimple(@RequestBody EduEntryTraining eduEntryTraining) {
	        Result result = new Result();
	        try {
	            result = eduEntryTrainingService.find(eduEntryTraining);
	        } catch (Exception e) {
	            e.printStackTrace();
	            result.setFalse(e.getMessage());
	        }
	        return result;
	    }
//	  
//	  @RequestMapping(value = "/show", method = {RequestMethod.POST})
//	  public Result show(int planId) {
//	        Result result = new Result();
//	        try {	            
//	            result = eduEntryTrainingService.show(planId);  
//	        } catch (Exception e) {
//	            e.printStackTrace();
//	            result.setFalse(e.getMessage());
//	        }
//	        return result;
//	    }
}
